﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

namespace Cloak.Mvp
{
	/// <summary>
	/// Binds a presenter type to a view class
	/// </summary>
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
	public class PresenterAttribute : Attribute, IPresenterDeclaration
	{
		/// <summary>
		/// Initializes a new attribute with the specified presenter type
		/// </summary>
		/// <param name="type">The type of presenter bound to the view class</param>
		public PresenterAttribute(Type type)
		{
			Contract.Requires(type != null);

			Type = type;
		}

		#region IPresenterDeclaration
		/// <summary>
		/// Gets a reference to the presenter declaratively bound to the view
		/// </summary>
		/// <returns>The presenter declaratively bound to the view</returns>
		public virtual IPresenterReference GetReference()
		{
			return new PresenterReference(Type);
		}
		#endregion

		/// <summary>
		/// Gets the type of presenter bound to the view class
		/// </summary>
		public Type Type { get; private set; }
	}
}